
<template>
	<el-select v-model="value" value-key="id" placeholder="请选择学期" @change="selectchange" size="large">
				<el-option v-for="item in options" :key="item.id" :label="item.academicYear+item.term" :value="item" />
			</el-select><br>
			当前学期:{{ value ? value.academicYear+value.term : '未选择' }}
	<div>
		<el-table :data="tableData" stripe style="width: 100%">
			<el-table-column prop="college" label="学院" width="230" />
			<el-table-column prop="major" label="专业" width="230" />
			<el-table-column prop="class" label="班级" width="230" />
			<el-table-column prop="date" label="更新日期" width="390" />
			<el-table-column prop="date" label="详细" width="120">
				<template #default="scope">
					<el-button type="primary" @click="ToExp(scope.row)">查看</el-button>
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>
<script lang='ts' setup>
//@ts-nocheck
import { getAllClass,GetSemester } from '@/api/request.js'
import { InfoFilled } from '@element-plus/icons-vue'
const result = ref([])
const jwtToken = localStorage.getItem('jwtToken')
const tableData = ref([])
const router = useRouter()
const value = ref()
const term=ref()
term.value=2
const options = ref([
	{ id: 1, label: '2022-2023学年上学期', desc: '2022-2023学年上学期' },
	{ id: 2, label: '2022-2023学年下学期', desc: '2022-2023学年下学期' },
	{ id: 3, label: '2023-2024学年上学期', desc: '2023-2024学年上学期' },
	{ id: 4, label: '2023-2024学年下学期', desc: '2023-2024学年下学期' },
])
onMounted(() => {
	getAllClass(jwtToken,term.value).then((res) => {
		console.log(res.data.data);
		result.value = res.data.data
		console.log("处理前的数据：", result.value);
		result.value = result.value.map((item) => ({
			college: item.college,
			major: item.major,
			class: item.cid,
			date: item.updateTime,
		}))
		console.log("处理后的数据：", result.value);
		tableData.value = result.value
	})
	let result=GetSemester(jwtToken).then((result)=>{
		console.log("result",result.data.data);
		options.value=result.data.data
		term.value=result.data.data.id
	})
})
const ToExp = (row) => {
	console.log("row", row.class);
	router.push({
		path: `/root/expmanage`,
		query: {
			cid: row.class,
		},
	})

}
const selectchange = (e) => {
	console.log(e.id);
	term.value=e.id
	getAllClass(jwtToken,term.value).then((res) => {
		console.log(res.data.data);
		result.value = res.data.data
		console.log("处理前的数据：", result.value);
		result.value = result.value.map((item) => ({
			college: item.college,
			major: item.major,
			class: item.cid,
			date: item.updateTime,
		}))
		console.log("处理后的数据：", result.value);
		tableData.value = result.value
	})
}
</script>
<style scoped lang='scss'></style>